﻿package
{
	import flash.display.MovieClip;
	import fl.transitions.easing.Regular;
	import fl.transitions.Tween;
	import flash.events.MouseEvent;
	
	public class BtnRoll_DisplaceRight
	{
		//VARIABLES INTERNAS SETEABLES OBLIGATORIAS.
		public var targetClip:MovieClip;
		
		//VARIABLES INTERNAS SETEABLES.
		public var useHand:Boolean = true;
		public var displacement:Number = 50;
		public var overTime:Number = 0.25;
		public var outTime:Number = 0.25;
		
		//VARIABLES INTERNAS.
		private var initX:Number;
		private var xTween:Tween;
		
		//CONSTRUCTOR.
		public function BtnRoll_DisplaceRight() {}
		
		//INIT.
		public function init()
		{
			//SETEA PROPIEDADES EN EL BOTON.
			targetClip.active = true;
			targetClip.rollAdmin = this;
			
			//SETEA LA MANITO.
			targetClip.hit.buttonMode = useHand;
			targetClip.hit.useHandCursor = useHand;
			
			//REGISTRA LA POSICION INICIAL.
			initX = targetClip.subClip.x;
			
			//ACTIVA EL ROLL OVER Y ROLL OUT DEL CLIP.
			targetClip.hit.addEventListener(MouseEvent.MOUSE_OVER, rollOverHandler);
			targetClip.hit.addEventListener(MouseEvent.MOUSE_OUT, rollOutHandler);
		}
		
		//MOUSE HANDLERS.
		public function rollOverHandler(event:MouseEvent)
		{
			if(targetClip.active)
				xTween = new Tween(targetClip.subClip, "x", Regular.easeIn, targetClip.subClip.x, initX + displacement - targetClip.subClip.width, overTime, true);
		}
		public function rollOutHandler(event:MouseEvent)
		{
			if(targetClip.active)
			{
				xTween.stop();
				xTween = new Tween(targetClip.subClip, "x", Regular.easeOut, targetClip.subClip.x, initX, outTime, true);
			}
		}
		
		//INFO.
		public function info():void
		{
			//VARIABLES INTERNAS SETEABLES OBLIGATORIAS.
			var str:String = "BtnRoll_DisplaceRight v1.0" + String.fromCharCode(13);
			str += "---------------" + String.fromCharCode(13);
			str += "VARIABLES SETEABLES OBLIGATORIAS:" + String.fromCharCode(13);
			str += "targetClip:Clip" + String.fromCharCode(13);
			str += "---------------" + String.fromCharCode(13);
			str += "VARIABLES SETEABLES OPCIONALES:" + String.fromCharCode(13);
			str += "useHand:Boolean [default = true]" + String.fromCharCode(13);
			str += "displacement:Number [default = 50]" + String.fromCharCode(13);
			str += "overTime:Number [default = 0.25]" + String.fromCharCode(13);
			str += "outTime:Number [default = 0.25]" + String.fromCharCode(13);
			str += "---------------" + String.fromCharCode(13);
			str += "NOTAS:" + String.fromCharCode(13);
			str += "No hay notas por ahora." + String.fromCharCode(13);
			str += "---------------";
			trace(str);
		}
	}
}